﻿using GrainManage.Data.Model;
using GrainManage.Data.Model.Table;
using GrainManage.Data.Service.Util;
using System;
using System.Collections.Generic;
using System.Data;

namespace GrainManage.Data.Service
{
    public class StatusService : BaseService, GrainManage.Data.Service.Interfaces.IStatusService
    {
        public StatusService(GrainManage.Data.Access.IAccess proc) : base(proc) { }

        public string GetMessage(int statusCode)
        {
            var mess = Proc.ExecuteScalar(ProcConst.Status_GetMessByCode, statusCode);
            return mess == null ? string.Empty : mess as string;
        }

        public List<StatusTable> Search(string message, IPageable page, ICountable records)
        {
            var result = Proc.ExecuteQuery(ProcConst.Status_Search, message, page.PageIndex, page.PageSize);
            return ConvertToModel<StatusTable>(result, records);
        }

        public Dictionary<int, string> GetOverView(IPageable page, ICountable records)
        {
            var dic = new Dictionary<int, string>();
            var result = Proc.ExecuteQuery(ProcConst.Status_GetOverViewByExtent, page.PageIndex, page.PageSize);
            records.Total = GetTotalRowCount(result);
            foreach (DataRow row in result.Tables[0].Rows)
            {
                int stateCode = Convert.ToInt32(row[0]);
                dic[stateCode] = Convert.ToString(row[1]);
            }
            return dic;
        }
    }
}
